/*
 * NodeImpl.h
 *
 *  Created on: Apr 25, 2012
 *      Author: REZNIK
 */

#ifndef NODEIMPL_H_
#define NODEIMPL_H_

#include "Node.h"

namespace cs236703_spring2012_hw2{

class NodeImpl : public Node
{
private:
	Node* next;
	Node* prev;
	int ref;
	bool removed;
	bool added;
public:
	NodeImpl() :	next(NULL), prev(NULL),
					ref(0), removed(false), added(false) {}

	virtual ~NodeImpl(){}

	virtual void SetValue(int _value) = 0;

	virtual int GetValue() const = 0;

	virtual void SetNext(Node* _next){ next = _next; }

	virtual Node* GetNext() const{ return next; }
	// Set given node as previous in list
	virtual void SetPrev(Node* _prev){ prev = _prev; }
	// Get the previous node in the list
	virtual Node* GetPrev() const{ return prev;}
	// Indicate whether the node is mutable or not
	virtual bool IsImmutable() const = 0;
	// Tell the node someone is pointing to it
	virtual void AddRef() { ref++; }
	// Tell the node it is no longer pointed by someone
	virtual void RemoveRef() {
		if(--ref == 0) delete this;
	}
	void SetRemoved(){ removed=true; }
	bool IsRemoved(){ return removed; }
	void SetAdded(){ added=true; }
	void SetMoved(){ added=false; }
	bool IsAdded(){ return added; }
};

};
#endif /* NODEIMPL_H_ */
